package com.shmn.gongjiajumain.service.impl;

import com.shmn.gongjiajumain.service.UserService;
import com.shmn.gongjiajumain.utils.DateUtil;
import com.shmn.gongjiajumain.vo.ScrapSubmitHistory.ScrapSubmitHistoryTableVo;
import com.shmn.gongjiajumain.vo.scrapSubmit.ScrapSubmitTableVo;
import com.shmn.gongjiajumain.vo.scrapSubmit.ScrapSubmitUpdateVo;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.beans.BeanUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.shmn.common.utils.PageUtils;
import com.shmn.common.utils.Query;

import com.shmn.gongjiajumain.dao.ScrapSubmitDao;
import com.shmn.gongjiajumain.entity.ScrapSubmitEntity;
import com.shmn.gongjiajumain.service.ScrapSubmitService;

import javax.annotation.Resource;


@Service("scrapSubmitService")
public class ScrapSubmitServiceImpl extends ServiceImpl<ScrapSubmitDao, ScrapSubmitEntity> implements ScrapSubmitService {

    @Resource
    private UserService userService;

    @Override
    public ScrapSubmitUpdateVo getByInfoId(Integer id) {
        ScrapSubmitEntity scrapSubmitEntity = baseMapper.selectById(id);
        ScrapSubmitUpdateVo scrapSubmitUpdateVo = new ScrapSubmitUpdateVo();
        BeanUtils.copyProperties(scrapSubmitEntity,scrapSubmitUpdateVo);
        scrapSubmitUpdateVo.setSubmitTime(DateUtil.formatDate(new Date()));
        scrapSubmitUpdateVo.setFirstAcceptorName(userService.getById(scrapSubmitEntity.getFirstAcceptor()).getName());
        scrapSubmitUpdateVo.setFirstTime(DateUtil.formatDate(scrapSubmitEntity.getFirstTime()));
        return scrapSubmitUpdateVo;
    }

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<ScrapSubmitEntity> page = this.page(
                new Query<ScrapSubmitEntity>().getPage(params),
                new QueryWrapper<ScrapSubmitEntity>()
        );
        PageUtils pageUtils = new PageUtils(page);
        List<ScrapSubmitTableVo> scrapSubmitTableVos = new ArrayList<>();
        pageUtils.getList().forEach(item->{
            ScrapSubmitTableVo scrapSubmitTableVo = new ScrapSubmitTableVo();
            BeanUtils.copyProperties(item,scrapSubmitTableVo);
            scrapSubmitTableVo.setSubmitTime(DateUtil.formatDate(new Date()));
            scrapSubmitTableVos.add(scrapSubmitTableVo);
        });
        pageUtils.setList(scrapSubmitTableVos);
        return pageUtils;
    }

}